//
//  Cache.m
//  Korea
//
//  Created by 杨东奇 on 15/9/8.
//  Copyright (c) 2015年 KoreaGo. All rights reserved.
//

#import "Cache.h"

@implementation Cache

+ (void)saveCache:(int)type andID:(NSString *)url andString:(NSString *)str{
    NSUserDefaults *cache = [NSUserDefaults standardUserDefaults];
    NSString *key = [NSString stringWithFormat:@"detail-%d-%@", type, url];
    [cache setObject:str forKey:key];
    [cache synchronize];
}
+ (NSString *)getCache:(int)type andID:(NSString *)url{
    NSUserDefaults *cache = [NSUserDefaults standardUserDefaults];
    NSString *key = [NSString stringWithFormat:@"detail-%d-%@", type, url];
    NSString *value = [cache objectForKey:key];
    
    return value;
}
+ (NSDictionary *)JOSNDatawithCache:(NSString *)cache{

//    id url = [[NSString alloc] initWithData:cache encoding:NSUTF8StringEncoding];
//    
//    NSData *data = [url dataUsingEncoding:NSUTF8StringEncoding];
//    
//    id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    NSData *data = [cache dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    NSMutableDictionary *dic = [NSJSONSerialization  JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
        
    return dic;

    
}
@end
